package com.central.post.controller

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.central.common.annotation.LoginUser
import com.central.common.entity.Post
import com.central.common.model.CommonResult
import com.central.common.model.PageVo
import com.central.common.model.SysUser
import com.central.post.pojo.post.*
import com.central.post.service.PostService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiModelProperty
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import springfox.documentation.annotations.ApiIgnore

/**
 * @author  fly
 * @date  2021/5/26 14:55
 * @version 1.0
 */
@Api(tags = ["(小程序) 帖子模块"])
@RestController
@RequestMapping("post")
open class PostController {

    @Autowired
    private lateinit var postService: PostService


    @ApiOperation("插入或者更新帖子")
    @PostMapping("/insertOrUpdatePost")
    fun insertOrUpdatePost(postSaveOrUpdateDto: PostSaveOrUpdateDto, @ApiIgnore @LoginUser sysUser: SysUser): CommonResult<Boolean> =
        postService.insertOrUpdatePost(postSaveOrUpdateDto, sysUser)


    @ApiOperation("获取帖子列表")
    @PostMapping("/getPostList")
    fun getPostList(postDto: PostDto, @ApiIgnore @LoginUser sysUser: SysUser): CommonResult<Page<PostVo>> =
        postService.getPostList(postDto, sysUser)

    @ApiOperation("获取帖子详情")
    @PostMapping("/getPostDetail")
    fun getPostDetail(postDto: PostDto, @ApiIgnore @LoginUser sysUser: SysUser): CommonResult<PostVo> =
        postService.getPostDetail(postDto, sysUser)

    @ApiOperation("移除帖子")
    @PostMapping("/removePost")
    fun removePost(id: Long, @LoginUser @ApiIgnore sysUser: SysUser): CommonResult<Boolean> =
        postService.removePost(id, sysUser)

    @ApiOperation("回复话题帖子")
    @PostMapping("/insertOrUpdateTopicPost")
    fun insertOrUpdateTopicPost(topicPostSaveDto: TopicPostSaveDto, @ApiIgnore @LoginUser sysUser: SysUser): CommonResult<Boolean> =
        postService.insertOrUpdateTopicPost(topicPostSaveDto, sysUser)

    @ApiOperation("获取话题帖子详情信息")
    @GetMapping("/getTopicDetail")
    fun getTopicDetail(topicId: Long, @ApiIgnore @LoginUser sysUser: SysUser): CommonResult<TopicPostDetailVo> =
        postService.getTopicDetail(topicId, sysUser)

    @ApiOperation("获取话题帖子列表信息")
    @GetMapping("/getTopicPostList")
    fun getTopicPostList(topicPostSearchDto: TopicPostSearchDto, pageVo: PageVo, @ApiIgnore @LoginUser sysUser: SysUser): CommonResult<Page<PostVo>> =
        postService.getTopicPostList(topicPostSearchDto, pageVo, sysUser)

    @ApiOperation("获取所有的帖子列表")
    @GetMapping("/getAllPostList")
    fun getAllPostList(type: Int? = 1, @ApiIgnore @LoginUser sysUser: SysUser, pageVo: PageVo): CommonResult<Page<PostVo>> =
        postService.getAllPostList(type!!, sysUser, pageVo)


    @ApiOperation("(rpc) 获取我获得的总赞数")
    @GetMapping("/getMyPostLikeNum/{userId}")
    fun getMyPostLikeNum(@PathVariable userId: Long): Long = postService.getMyPostLikeNum(userId)


    @ApiOperation("(rpc) 获取帖子详情")
    @GetMapping("/getPostDetail/{id}")
    fun getPostDetail(@PathVariable id: Long): Post? = postService.getPostDetail(id)
}